import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

// const datacenterUrl = CommonConfig.datacenterUrl + '/v1'
const schemaUrl = CommonConfig.schemaUrl + '/v1'
const tpmUrl = CommonConfig.tpmUrl + '/v1'

// 已设置布局车间
export function getWorkshops (isSet = false) {
  let url = schemaUrl + '/workshops/dis_layout'
  isSet && (url = schemaUrl + '/workshops/set_layout')

  return axiosInstance.get(url).then(resp => {
    return Promise.resolve(resp.data)
  })
}

// 设置布局车间
export function insertMachineLayout (params) {
  let url = tpmUrl + '/device_layout'

  return axiosInstance.post(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}
// 删除车间设备布局
export function deleteMachineLayout (workshopId) {
  let url = `${tpmUrl}/workshops/${workshopId}/device_layout `

  return axiosInstance.delete(url).then(resp => {
    return Promise.resolve(resp)
  })
}
// 获取车间布局
export function getWorkshopLayout (workshopId) {
  let url = `${tpmUrl}/workshops/${workshopId}/device_layout`

  return axiosInstance.get(url).then(resp => {
    return Promise.resolve(resp.data)
  })
}

// 获取车间下设备列表
export function getDevicesByWorkshopId (workshopId) {
  let url = `${tpmUrl}/devices_dis_layout/${workshopId}`
  return axiosInstance.get(url).then(resp => {
    return Promise.resolve(resp.data)
  })
}

// 添加设备
export function setDevice (params) {
  let url = `${tpmUrl}/device_layout/device`
  return axiosInstance.post(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

// 修改设备
export function updateDevice (params) {
  let url = `${tpmUrl}/device_layout/device`
  return axiosInstance.put(url, params).then(resp => {
    return Promise.resolve(resp)
  })
}

// 删除设备
export function delDevice (id) {
  let url = `${tpmUrl}/device_layout/${id}/device`
  return axiosInstance.delete(url).then(resp => {
    return Promise.resolve(resp)
  })
}
// 获取车间下产线列表
export function getLines (workshopId) {
  let url = `${schemaUrl}/workshop/${workshopId}/dis_set_layout_lines`
  return axiosInstance.get(url).then(resp => {
    return Promise.resolve(resp.data)
  })
}
